<?php
namespace app\common\model;
/**
 * 文档栏目
 */
class Category extends BaseModel {

    protected $name = 'category';

    protected $autoWriteTimestamp = true;

    public $error = "";
    /**
     * 获取单个分类
     */
    public static function detail($id){
        return self::where(['status'=>1 , 'id'=>$id])->find();
    }

    public static function getAll($fields = "*"){
        return self::field($fields)->where('status', 1)->select();
    }
    /**
     * 删除栏目
     */
    public function remove(){
        $count = self::where('parent_id' , $this->id)->count();
        if($count > 0){
            $this->error = "请先删除子栏目！";
            return false;
        }
        return $this->delete();
    }
}